import iconList from '@/icon/iconlist'
export default {
  column: [],
  /**
   * 构建表单元素
   * @param {*} vm 当前vue实例
   * @returns 
   */
  buildColumn(vm) {
    if(!vm) {
      return this.column
    }
    this.column = [
      {
        label:'主键',
        prop:'id',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: true,
        span: 12,
        readonly: false,
        display: false,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '主键不能为空', trigger: "blur" }
        ]},
      {
        label:'单行文本',
        prop:'text',
        search: true,
        searchType: 'EQ',
        searchSpan: 8,
        hide: false,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: true, message: '单行文本不能为空', trigger: "blur" }
        ]},
      {
        label:'密码',
        type: 'password',
        prop:'password',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '密码不能为空', trigger: "blur" }
        ]},
      {
          label:'多行文本',
          type: "textarea",
          prop:'textarea',
          search: false,
          hide: false,
          span: 24,
          readonly: false,
          display: true,
          value: '',
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          rules: [
            { required: false, message: '多行文本不能为空', trigger: "blur" }
          ]},
      {
          label:'枚举字典',
          prop:'status',
          type: 'select',
          dicUrl: '/sys/dict/getByDictKey',
          dicMethod: 'post',
          search: true,
          searchType: 'EQ',
          searchSpan: 8,
          hide: false,
          span: 24,
          readonly: false,
          display: true,
          value: Number('10'),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
            dictKey: 'sys_demo_status',
            type: 'enum'
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data.items',
            label: 'name',
            value: 'dictItemValue'
          },
          rules: [
            { required: true, message: '枚举字典不能为空', trigger: "blur" }
          ]},
      {
          label:'db字典',
          prop:'dbDict',
          type: 'select',
          dicUrl: '/sys/dict/getByDictKey',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: false,
          span: 24,
          readonly: false,
          display: true,
          value: Number(''),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
            dictKey: 'user_type',
            type: 'db'
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data.items',
            label: 'name',
            value: 'dictItemValue'
          },
          rules: [
            { required: false, message: 'db字典不能为空', trigger: "blur" }
          ]},
      {
          label:'远程下拉',
          prop:'remoteSelect',
          type: 'select',
          dicUrl: '/sys/demo/select',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: false,
          span: 24,
          readonly: false,
          display: true,
          value: '',
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          rules: [
            { required: false, message: '远程下拉不能为空', trigger: "blur" }
          ]},
      {
        label:'图标选择器',
        prop:'inputIcon',
        type: 'icon',
        iconList:  iconList,
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '图标选择器不能为空', trigger: "blur" }
        ]},
      {
        label:'单图',
        prop:'image',
        type: 'upload',
        action: '/sys/upload/image',
        propsHttp: {
          res: 'data'
        },
        limit: 1,
        listType: 'picture-card',
        multiple: false,
        hide: false,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '单图不能为空', trigger: "blur" }
        ]},
      {
        label:'多图',
        prop:'images',
        type: 'upload',
        action: '/sys/upload/image',
        listType: 'picture-card',
        propsHttp: {
          res: 'data'
        },
        multiple: true,
        hide: true,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '多图不能为空', trigger: "blur" }
        ]},
      {
        label:'附件',
        prop:'attachment',
        type: 'upload',
        action: '/sys/upload/file',
        limit: 1,
        multiple: false,
        propsHttp: {
          res: 'data'
        },
        hide: false,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '附件不能为空', trigger: "blur" }
        ]},
      {
        label:'多附件',
        prop:'attachments',
        type: 'upload',
        action: '/sys/upload/file',
        multiple: true,
        propsHttp: {
          res: 'data'
        },
        hide: true,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '多附件不能为空', trigger: "blur" }
        ]},
      {
          label:'树',
          prop:'deptId',
          type: 'tree',
          dicUrl: '/sys/dept/tree',
          dicMethod: 'post',
          search: false,
          searchType: '',
          searchSpan: 8,
          hide: false,
          span: 24,
          readonly: false,
          display: true,
          value: Number(''),
          addDisabled: false,
          addDisplay: true,
          addDetail: false,
          editDisabled: false,
          editDisplay: true,
          editDetail: false,
          dicQuery: {
          },
          dicFlag: true, // 表格打开表单的时候是否重新拉取字典
          props: {
            res: 'data',
            label: 'name',
            value: 'id'
          },
          rules: [
            { required: false, message: '树不能为空', trigger: "blur" }
          ]},
      {
        label:'日期',
        prop:'demoDate',
        type: 'datetime',
        valueFormat: 'yyy-MM-dd',
        format: 'yyyy-MM-dd',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '日期不能为空', trigger: "blur" }
        ]},
      {
        label:'时间',
        prop:'demoDatetime',
        type: 'datetime',
        valueFormat: 'yyy-MM-dd HH:hh:ss',
        format: 'yyyy-MM-dd HH:hh:ss',
        search: false,
        searchType: '',
        searchSpan: 8,
        hide: false,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '时间不能为空', trigger: "blur" }
        ]},
      {
        label:'富文本',
        prop:'editor',
        component: 'avue-ueditor',
        params: {
          options: {
            action: '/sys/upload/image',
            props: {
              res: "data",
              url: "url"
            },
          }
        },
        hide: true,
        span: 24,
        readonly: false,
        display: true,
        value: '',
        addDisabled: false,
        addDisplay: true,
        addDetail: false,
        editDisabled: false,
        editDisplay: true,
        editDetail: false,
        rules: [
          { required: false, message: '富文本不能为空', trigger: "blur" }
        ]},
    ]
    return this.column
  },
  /**
   * 动态构建搜索条件
   * @param {*} vm 当前vue实例
   * @returns 
   */
  buildSearchParam(vm) {
    let res = {}
    vm.option.column.forEach(item=>{
      if(item.search) {
        let key = `m_${item.searchType}_${item.prop}`
        let value = vm.search[item.prop]
        if(value!== undefined) {
          res[key] = value
        }
      }
    })
    return res;
  }
}